package main

import (
	"fmt"
	"sync/atomic"
	"time"
)

func main() {
	var opts int64 = 0


   for i := 0; i < 50; i++ {
       // 注意第一个参数必须是地址
       atomic.AddInt64(&opts, 1) //加操作
       //atomic.AddInt64(&opts, -1) 减操作
       time.Sleep(time.Millisecond)
   }
   time.Sleep(time.Second)

   fmt.Println("opts: ", atomic.LoadInt64(&opts))

}
